<?php

$rootdir = '../';
include_once('session.php');

global $desql;
$desql->Connect();

function CreatePortrait($Texte)
{
	global $desql;
	
	$result = $desql->Query('INSERT INTO portraits(texte) 
										VALUES(\''. mysql_real_escape_string($Texte) . '\'
												)');
	$id = mysql_insert_id();
	if($result == false)
		return false;
	else 
		return $id;
}

function GetAllPortraits()
{
	global $desql;
	$portraits = array();
	
	$answer = $desql->Query('SELECT * FROM portraits');
	if($answer == false)
		return false;
		
	while($portrait = mysql_fetch_array($answer))
		$portraits[] = $portrait;
	
	return $portraits;
}

function DeletePortraitsById($Id)
{
	global $desql;
	
	if(is_numeric($Id) == false)
		return false;
	else
		return $desql->Query('DELETE FROM portraits WHERE id=' . $Id);
}

function GetAdminPortraitsHTMLContent()
{
	$HTML = '<div style="margin-top: 20px; margin-left: 20px;">';
		
	$HTML .= '
		<table style="font-size: 80%; margin: auto; text-align: center; ">
			<tr>
				<th style="border: 1px solid gray; width: 450px;">Portrait</th>
				<th style="border: 1px solid gray; width: 100px;">Options</th>
			</tr>
			<tr>
				<td style="border: 1px solid gray;"></td>
				<td style="border: 1px solid gray;"><div id="icone-nouveau"><a href="cadre_admin.php?type=7&new=1"></a></div></td>
			<tr>' . GetAdminPortraitHTMLContent() . '
		</table>
	';
	return $HTML . '</div>';
}

function GetAdminPortraitHTMLContent()
{
	$portraits = GetAllPortraits();
	$HTML = '';
	
	if($portraits == false)
		return '';
	
	foreach($portraits as $portrait)
	{
		$HTML .= '
			<tr>
				<td style="border: 1px solid gray;">
					<img width=400 src="images_portraits/' . $portrait['id'] . '.png" />
					<p>' . stripslashes($portrait['texte']) . '</p>
				</td>
				<td style="border: 1px solid gray;">
					<div id="icone-supprimer">
						<a href="cadre_admin.php?type=7&deleteid=' . $portrait['id'] . '" onClick="return(confirm(\'Etes-vous sûr de vouloir supprimer ce portrait?\'));"></a>
					</div>
				</td>
			</tr>
		';
	}

	return $HTML;
}

function GetCreatePortraitForm()
{
	$HTML = '
		<h4>Nouveau portrait</h4>
		<form enctype="multipart/form-data" style="margin-left: 20px; margin-top: 20px; font-size: 80%;" method="post">
			<br />
			<table style="margin: auto;">
				<tr>
					<td style="width: 150px;"><label for="portraitimage">Fichier (PNG uniquement) :</label></td>
					<td><input type="file" tabindex="1" name="portraitimage" size="30" /><br /></td>
				</tr>
				<tr>
					<td><label for="categorie">Texte :</label></td>
					<td>
						<textarea tabindex="2" name="portraittexte" rows="8" cols="80">
Texte normal ligne 1 : <a target="_blank" href="http://lien.com">Texte du lien</a> <br />
Texte normal ligne 2,<br />
<a target="_blank" href="http://lien2.com">Texte du lien de la ligne 3</a>
						</textarea>
					</td>	
				</tr>
				<tr>
					<td></td>
					<td>
						<p><u>Règles</u> :<br />
lien : &#60;a target="_blank" href="adresse"&#62;texte&#60;/a&#62; (target="_blank" permet d\'ouvrir le lien dans un nouvel onglet)<br />
sauter une ligne : &#60;br /&#62;</p>
					</td>
				</tr>	
				<tr>
					<td></td>
					<td><br /><input type="submit" name="send" tabindex="3" value="Envoyer" /></td>
				</tr>
			</table>
		</form>
	';
	
	return $HTML;
}

?>